package com.huiminpay.paymentagent;

import com.huiminpay.paymentagent.api.PayChannelAgentService;
import com.huiminpay.paymentagent.api.conf.AliConfigParam;
import com.huiminpay.paymentagent.api.dto.PaymentResponseDTO;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class PayChannelAgentServiceImpl {

    @Autowired
    PayChannelAgentService agentService;

    @Test
    public  void testQueryPayOrderByAli(){

        //支付宝网关地址  测试使用  https://openapi.alipaydev.com/gateway.do  正式的:https://openapi.alipay.com/gateway.do
        String serverUrl = "https://openapi.alipaydev.com/gateway.do";
        //沙箱应用Id
        String APP_ID = "2021000121613030";
        //应用私钥
        String APP_PRIVATE_KEY = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCvNSWiTwAos5is5lViqxLI3IrWMVSKRFCyXq10XLrgmbKnk7P3VZgUSwsUcIXW6/8pb2JB4ycDMgFvyNPfOAxf2oeBq3AWFbRUWjRGKzJSa/jaKGuhN8A9tvvAAAAAhSrOzBsQeVvImDlxY07/0l5PA3qoy/R2uGHenC0EroCxrB/RiE6fZwwYGCijfAEAYjIC4s3jAYI/cb7PDn2xTk2w5queY75k2wMFLmdELeyvEaspUaYIwp07pYUY4TP/12/3QFtvEPgD8UcwsL7Ghgvr01QoImRfDWSUmBgZFVoFAzHmz+Jh5h1VxMADp8WlbmH3CReBwXM2xtRsvC2GCqxnAgMBAAECggEAdkWaMgbCRLd3yL9zxDdXZt/5mL2UJAIZt07SKEqwnA0k3JqIUd4l2w0NXa7Xqk2E4aOe4HtGSpHnBl67J2PedpY+AvqHn2Dnakm6H+PpBFp+kkXW4e2QiBiNuP5HAhLi4tZFLsm9e5vGqxQur+KCZzQiCPAlBj9RUcR7Xz2tAkHe8b/fG40EwytEC3p3idEb4KSgQBHEs+ck6KeYc+ZDNV4p2tK6dQDeGaimWsfINnzoY3s8TotPKU9ZfwecZ83jpaYd2so50f830OQuiEF9CxtcSTNIc3mqL01FH395oSxYcAT09Shg8UshvfVLysgsyWPTWNpqsGL/b/PFMn4PAQKBgQDvB4P4Za3nb/KVUIDuddOvFwIh78ZjvmYcRVQRsoIfNUVy0Efcw4IoZ4H/zqJCgx87c3vwNoCi8CHdi3RfOBnl5ZJc0OhbGMl+e9kEN+YbkL2ajfZKBdJCXrMslEYFSZ/YP+8s4/4UNruOaztatTSetQtqKhf8ZH84VAPHhPYfzwKBgQC7paM1kbPFejlY3QjxXuYQkVNhZCyOOPHwCJdTTQpD/PbeS/PyQEBksXKhZejJ8ErFEn4IWfHPxXVhSgQkl7iomhhDT7EO0jKPTXKJIwoyY6WPiraCYEFZtc4GkpQdo759372XEKuiYzOsT8uh12PAv7gSR8AI3AO+zJicl/n36QKBgFn0oh3hZkkrQEghO+SCQ2ApcIwFCMyQ4yzQior+eynzimdjKyhSC7HZAnua8EXHwwFEvOfyGwc3CAewa+NJ4bU7aJG1rTxbX7lSMqH7x4WoOzLnKkFBX5fKu/OS+acTxixEI2bphr1ku8ElafkBKQRxbhJONSivSZGRTLrRty7RAoGAEH1CtU9ja8QMzAlIYuWC9AvBNvq1i53nbL9khNZtQ4I0M16bRjttLSwGtbYd2bj66Qxx9MvqmuZwJSd667hFatN3tFqJZZMFDGCy4ugoWjs1bkKzPQu2UmrOevdgeqZL9AW4RFEbs/5hqQ+uBj/GLUbrpveVIXIsBhU2h/Q27BkCgYEAyCRrIIfarYM9mvaKwxi0Z2+5fCQArkXIzhZrpBgI7Eo0svGi5kW4bZbadxgDBXlSeY726ce55BOl0kFFEedW/qXOEoQrUCi/8PrbJt6qEs0K2C/47eRk1m/KhrhdItMMqjNA7CgFmtaPqKileJYqp0aP8Qnnj/jELCAj+RgjUTQ=";
        //编码方式
        String CHARSET = "UTF-8";
        //支付宝公钥
        String ALIPAY_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlwmUoocEpVm54QaspsDIZHfL8R7uI1EZpLfLALu2rR/u9Mi0M9ohX8hb3ldGMqqHSGIfsHnj6+lDGEMWIfFVZtF1gvEjWFqarrJ1pwFsNlG235Jb3IP9hs7DPjJFjyMgD9tPKn0ik7i+chKWelbMFHMZdzJyx/izXZLudWRo60Ps79dzjC+9J3Unzvrep0grbdAv0WD5hC11nbSzjNWGuY+fJy/pTNwt0aaEW5QqWvQrox1cfcAo1N5XVepzkual6EuRyxN1//jS3reQryxj0htNCoGgEostDlvALXwN0GtumhgjcXeljYa6z2o7eM5oa18E7WWIOLI84gCzDWhquQIDAQAB";
        //签名类型
        String signType = "RSA2";


        AliConfigParam aliConfigParam = new AliConfigParam();
        aliConfigParam.setUrl(serverUrl);
        aliConfigParam.setCharest(CHARSET);

        aliConfigParam.setAlipayPublicKey(ALIPAY_PUBLIC_KEY);
        aliConfigParam.setRsaPrivateKey(APP_PRIVATE_KEY);
        aliConfigParam.setAppId(APP_ID);
        aliConfigParam.setFormat("json");
        aliConfigParam.setSigntype(signType);

        PaymentResponseDTO paymentResponseDTO = agentService.queryPayOrderByAli(aliConfigParam, "HM1256576878366364");
        System.out.println(paymentResponseDTO);
    }

}
